<template>
  <div>
    <div>
      <FormPanel
        ref="formPanel"
        :list="formList"
        :cols="2"
        :formType="type"
        labelWidth="110"
        :isSubmitBtn="false"
        @formChange="formChangeHandle"
      />
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">取消</el-button>
      <el-button @click="saveDialog" :disabled="isDisabled" type="primary">确定</el-button>
    </div>
  </div>
</template>

<script>
import {
  addTestDriveCars,
  editTestDriveCars
 } from '@/api/potenCus/basedata/searchTestDriveCars';
import { dictionary } from '@/utils/dictMixin';
import AjaxButton from '@/components/AjaxButton';
import { VIN, phone } from '@/utils/validate'

export default {
  name: 'addBYcar',
  mixins: [dictionary],
  props: {
    type: {
      type: String,
      default: 'add'
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    this.saveData = null;
    return {
      formList: this.createFormList(),
      isDisabled: false,
    };
  },
  created() {
    // this.init();
  },
  methods: {
    init() {
      let {rowData} = this
      console.log('编辑保有车', rowData, this.type)
      if(this.type === 'edit'){
        this.formList.forEach( x =>{
          x.initialValue = rowData[x.fieldName]
        })
      }
      // if (this.type === 'edit') {
      //   // 更新接口需要的记录 ID
      //   this.recordId = this.rowData.testDriveId;
        // this.formList.forEach(x => {
        //   x.initialValue = this.rowData[x.fieldName];
        // });
      // }
    },
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '品牌',
          fieldName: 'keepVehiclesBrand',
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入保有品牌', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '车系',
          fieldName: 'keepVehiclesSeries',
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入保有车系', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'keepVehiclesModel',
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入保有车型', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入',
          // rules: [{ required: false, trigger: 'blur', validator: VIN}],
        },
        {
          type: 'DATE',
          label: '购买日期',
          fieldName: 'buyDate',
          dateType: 'exactdate',
          placeholder: '请选择',
        },
        {
          type: 'INPUT_NUMBER',
          label: '购买车龄(天)',
          fieldName: 'boughtCarsAge',
          placeholder: '请输入',
        },
        {
          type: 'INPUT_NUMBER',
          label: '行驶里程(km)',
          fieldName: 'drivingMileage',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'keepingRemark',
          placeholder: '请输入',
        },

      ];
    },
    formChangeHandle(val) {
      this.saveData = val;
    },
    async saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.saveData !== null){
        console.log("保有保存",this.formList)
        let params={
          keepVehiclesBrand: this.formList[0].initialValue,
          keepVehiclesSeries: this.formList[1].initialValue,
          keepVehiclesModel: this.formList[2].initialValue,
          vin: this.formList[3].initialValue,
          buyDate: this.formList[4].initialValue,
          boughtCarsAge: this.formList[5].initialValue,
          drivingMileage: this.formList[6].initialValue,
          keepingRemark: this.formList[7].initialValue,
        }
        console.log("保有params",params)
        this.$emit('BYHandle', params);
        this.closeDialog('refresh');
      } else {
        this.$message.info('请填写必填项!');
      }
    },
    closeDialog(param) {
      this.$emit('close', false, param);
    },
  }
};
</script>

<style lang="less" scoped>
</style>
